import { Component } from 'react'
import './Login.scss'
import { Link } from 'react-router-dom'
class Login extends Component {
  state = {
    userinfo: {
      name: '',
      pass: '',
    },
  }
  // 账号
  username = (e) => {
    let userinfo = this.state.userinfo
    userinfo.name = e.target.value
    this.setState({
      name: userinfo,
    })
  }
  // 密码
  password = (e) => {
    let userinfo = this.state.userinfo
    userinfo.pass = e.target.value
    this.setState({
      pass: userinfo,
    })
    localStorage.setItem('username', this.state.userinfo.name)
  }
  // 登录
  subForm = (e) => {
    e.preventDefault()
  }
  render() {
    return (
      <div className="All">
        <div className="loginBox">
          <h2>login</h2>
          <form onSubmit={this.subForm}>
            <div className="item">
              <input type="text" onChange={this.username} required />
              <label>账号</label>
            </div>
            <div className="item">
              <input type="password" onChange={this.password} required />
              <label>密码</label>
            </div>
            {/* <button
              className="btn"
              onClick={this.btnLogin}
              type="submit"
              to="/Home"
            >
              登录
            </button> */}
            <Link className="btn" to="/Home">
              登录
            </Link>
          </form>
        </div>
      </div>
    )
  }
}

export default Login
